using System;
using System.Windows.Input;

namespace Exones.Blend.AssetsManager
{
	class DelegateCommand: ICommand
	{
		private readonly Action execute;
		private readonly Func<bool> canExecute;

		public DelegateCommand(Action execute, Func<bool> canExecute)
		{
			if (execute == null) throw new ArgumentNullException("execute");

			this.execute = execute;
			this.canExecute = canExecute;
		}

		public bool CanExecute(object parameter)
		{
			if (canExecute == null)
				return true;

			return canExecute();
		}

		public void Execute(object parameter)
		{
			execute();
		}

		public void NotifyCanExecuteChanged()
		{
			if (CanExecuteChanged != null)
			{
				var evt = CanExecuteChanged;				
				evt(this, EventArgs.Empty);
			}
		}

		public event EventHandler CanExecuteChanged;
	}
}